]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
c2a1d533801e829b765d61ddb292ba9831715be8
[friendica.git] / mod / contacts.php
1 <?php
2
3 function contacts_init(&$a) {
4         require_once('include/group.php');
5         $a->page['aside'] .= group_side();
6
7         if($a->config['register_policy'] != REGISTER_CLOSED)
8                 $a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
9 }
10
11 function contacts_post(&$a) {
12
13         
14         if(! local_user())
15                 return;
16
17         $contact_id = intval($a->argv[1]);
18         if(! $contact_id)
19                 return;
20
21         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
22                 intval($contact_id),
23                 intval($_SESSION['uid'])
24         );
25
26         if(! count($orig_record)) {
27                 notice("Could not access contact record." . EOL);
28                 goaway($a->get_baseurl() . '/contacts');
29                 return; // NOTREACHED
30         }
31
32         $profile_id = intval($_POST['profile-assign']);
33         if($profile_id) {
34                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
35                         intval($profile_id),
36                         intval($_SESSION['uid'])
37                 );
38                 if(! count($r)) {
39                         notice("Cannot locate selected profile." . EOL);
40                         return;
41                 }
42         }
43         $rating = intval($_POST['reputation']);
44         if($rating > 5 || $rating < 0)
45                 $rating = 0;
46
47         $reason = notags(trim($_POST['reason']));
48
49         $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
50                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
51                 intval($profile_id),
52                 intval($rating),
53                 dbesc($reason),
54                 intval($contact_id),
55                 intval($_SESSION['uid'])
56         );
57         if($r)
58                 notice("Contact updated." . EOL);
59         else
60                 notice("Failed to update contact record." . EOL);
61         return;
62
63 }
64
65
66
67 function contacts_content(&$a) {
68
69         if(! local_user()) {
70                 $_SESSION['sysmsg'] .= "Permission denied." . EOL;
71                 return;
72         }
73
74         if($a->argc == 3) {
75
76                 $contact_id = intval($a->argv[1]);
77                 if(! $contact_id)
78                         return;
79
80                 $cmd = $a->argv[2];
81
82                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
83                         intval($contact_id),
84                         intval($_SESSION['uid'])
85                 );
86
87                 if(! count($orig_record)) {
88                         notice("Could not access contact record." . EOL);
89                         goaway($a->get_baseurl() . '/contacts');
90                         return; // NOTREACHED
91                 }
92
93
94 //              $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
95 //              $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
96 //                              dbesc($photo),
97 //                              intval($_SESSION['uid'])
98 //              );
99         
100                 if($cmd == 'block') {
101                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
102                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
103                                         intval($blocked),
104                                         intval($contact_id),
105                                         intval($_SESSION['uid'])
106                         );
107                         if($r) {
108                                 $msg = "Contact has been " . (($blocked) ? '' : 'un') . "blocked." . EOL ;
109                                 notice($msg);
110                         }
111                         goaway($a->get_baseurl() ."/contacts/$contact_id");
112                         return; // NOTREACHED
113                 }
114
115                 if($cmd == 'drop') {
116                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
117                                 intval($contact_id),
118                                 intval($_SESSION['uid']));
119
120 //                      if(count($photos)) {
121 //                              foreach($photos as $p) {
122 //                                      q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
123 //                                              $p['id']);
124 //                              }
125 //                      }
126
127                         if(intval($contact_id))
128                                 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
129                                         intval($contact_id)
130                                 );
131         
132                         notice("Contact has been removed." . EOL );
133                         goaway($a->get_baseurl() . '/contacts');
134                         return; // NOTREACHED
135                 }
136         }
137
138         if(($a->argc == 2) && intval($a->argv[1])) {
139
140                 $contact_id = intval($a->argv[1]);
141                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
142                         $_SESSION['uid'],
143                         intval($contact_id)
144                 );
145                 if(! count($r)) {
146                         notice("Contact not found.");
147                         return;
148                 }
149
150                 require_once('view/contact_selectors.php');
151
152                 $tpl = file_get_contents("view/contact_edit.tpl");
153
154                 $direction = '';
155                 if(strlen($r[0]['issued-id'])) {
156                         if(strlen($r[0]['dfrn-id'])) {
157                                 $direction = DIRECTION_BOTH;
158                                 $dir_icon = 'images/lrarrow.gif';
159                                 $alt_text = 'Mutual Friendship';
160                         }
161                         else {
162                                 $direction = DIRECTION_IN;
163                                 $dir_icon = 'images/larrow.gif';
164                                 $alt_text = 'is a fan of yours';
165                         }
166                 }
167                 else {
168                         $direction = DIRECTION_OUT;
169                         $dir_icon = 'images/rarrow.gif';
170                         $alt_text = 'you are a fan of';
171                 }
172
173                 $o .= replace_macros($tpl,array(
174                         '$profile_select' => contact_profile_assign($r[0]['profile-id']),
175                         '$contact_id' => $r[0]['id'],
176                         '$block_text' => (($r[0]['blocked']) ? 'Unblock this contact' : 'Block this contact' ),
177                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">Currently blocked</div>' : ''),
178                         '$rating' => contact_reputation($r[0]['rating']),
179                         '$reason' => $r[0]['reason'],
180                         '$groups' => '', // group_selector(),
181                         '$photo' => $r[0]['photo'],
182                         '$name' => $r[0]['name'],
183                         '$dir_icon' => $dir_icon,
184                         '$alt_text' => $alt_text,
185                         '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
186
187                 ));
188
189                 return $o;
190
191         }
192
193         if(($a->argc == 2) && ($a->argv[1] == 'all'))
194                 $sql_extra = '';
195         else
196                 $sql_extra = " AND `blocked` = 0 ";
197
198         $tpl = file_get_contents("view/contacts-top.tpl");
199         $o .= replace_macros($tpl,array(
200                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
201                 '$hide_text' => ((strlen($sql_extra)) ? 'Show Blocked Connections' : 'Hide Blocked Connections')
202         )); 
203
204         switch($sort_type) {
205                 case DIRECTION_BOTH :
206                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
207                         break;
208                 case DIRECTION_IN :
209                         $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
210                         break;
211                 case DIRECTION_OUT :
212                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
213                         break;
214                 case DIRECTION_ANY :
215                 default:
216                         $sql_extra2 = '';
217                         break;
218         }
219
220         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
221                 intval($_SESSION['uid']));
222
223         if(count($r)) {
224
225                 $tpl = file_get_contents("view/contact_template.tpl");
226
227                 foreach($r as $rr) {
228                         if($rr['self'])
229                                 continue;
230                         $direction = '';
231                         if(strlen($rr['issued-id'])) {
232                                 if(strlen($rr['dfrn-id'])) {
233                                         $direction = DIRECTION_BOTH;
234                                         $dir_icon = 'images/lrarrow.gif';
235                                         $alt_text = 'Mutual Friendship';
236                                 }
237                                 else {
238                                         $direction = DIRECTION_IN;
239                                         $dir_icon = 'images/larrow.gif';
240                                         $alt_text = 'is a fan of yours';
241                                 }
242                         }
243                         else {
244                                 $direction = DIRECTION_OUT;
245                                 $dir_icon = 'images/rarrow.gif';
246                                 $alt_text = 'you are a fan of';
247                         }
248
249                         $o .= replace_macros($tpl, array(
250                                 '$id' => $rr['id'],
251                                 '$alt_text' => $alt_text,
252                                 '$dir_icon' => $dir_icon,
253                                 '$thumb' => $rr['thumb'], 
254                                 '$name' => $rr['name'],
255                                 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )
256                         ));
257                 }
258         }
259         return $o;
260 }