]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
7baeb3e14e3ca7dbf1daa6141dd219d3843edda6
[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( t('Could not locate selected profile.') . EOL);
40                         return;
41                 }
42         }
43         $priority = intval($_POST['priority']);
44         if($priority > 5 || $priority < 0)
45                 $priority = 0;
46
47         $rating = intval($_POST['reputation']);
48         if($rating > 5 || $rating < 0)
49                 $rating = 0;
50
51         $reason = notags(trim($_POST['reason']));
52
53         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
54                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
55                 intval($profile_id),
56                 intval($priority),
57                 intval($rating),
58                 dbesc($reason),
59                 intval($contact_id),
60                 intval($_SESSION['uid'])
61         );
62         if($r)
63                 notice( t('Contact updated.') . EOL);
64         else
65                 notice( t('Failed to update contact record.') . EOL);
66         return;
67
68 }
69
70
71
72 function contacts_content(&$a) {
73
74         if(! local_user()) {
75                 notice( t('Permission denied.') . EOL);
76                 return;
77         }
78
79         if($a->argc == 3) {
80
81                 $contact_id = intval($a->argv[1]);
82                 if(! $contact_id)
83                         return;
84
85                 $cmd = $a->argv[2];
86
87                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
88                         intval($contact_id),
89                         intval($_SESSION['uid'])
90                 );
91
92                 if(! count($orig_record)) {
93                         notice( t('Could not access contact record.') . EOL);
94                         goaway($a->get_baseurl() . '/contacts');
95                         return; // NOTREACHED
96                 }
97
98
99                 if($cmd == 'block') {
100                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
101                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
102                                         intval($blocked),
103                                         intval($contact_id),
104                                         intval($_SESSION['uid'])
105                         );
106                         if($r) {
107                                 $msg = t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL ;
108                                 notice($msg);
109                         }
110                         goaway($a->get_baseurl() ."/contacts/$contact_id");
111                         return; // NOTREACHED
112                 }
113
114                 if($cmd == 'ignore') {
115                         $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
116                         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
117                                         intval($readonly),
118                                         intval($contact_id),
119                                         intval($_SESSION['uid'])
120                         );
121                         if($r) {
122                                 $msg = t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL ;
123                                 notice($msg);
124                         }
125                         goaway($a->get_baseurl() ."/contacts/$contact_id");
126                         return; // NOTREACHED
127                 }
128
129                 if($cmd == 'drop') {
130                         $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
131                                 intval($contact_id),
132                                 intval($_SESSION['uid'])
133                         );
134
135                         q("DELETE FROM `item` WHERE `contact-id` = %d AND `uid` = %d ",
136                                         intval($contact_id),
137                                         intval($_SESSION['uid'])
138                         );
139                         q("DELETE FROM `photo` WHERE `contact-id` = %d AND `uid` = %d ",
140  
141                                         intval($contact_id),
142                                         intval($_SESSION['uid'])
143                         );
144         
145                         notice( t('Contact has been removed.') . EOL );
146                         goaway($a->get_baseurl() . '/contacts');
147                         return; // NOTREACHED
148                 }
149         }
150
151         if(($a->argc == 2) && intval($a->argv[1])) {
152
153                 $contact_id = intval($a->argv[1]);
154                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
155                         $_SESSION['uid'],
156                         intval($contact_id)
157                 );
158                 if(! count($r)) {
159                         notice( t('Contact not found.') . EOL);
160                         return;
161                 }
162
163                 require_once('view/contact_selectors.php');
164
165                 $tpl = file_get_contents("view/contact_edit.tpl");
166
167                 $direction = '';
168                 if(strlen($r[0]['issued-id'])) {
169                         if(strlen($r[0]['dfrn-id'])) {
170                                 $direction = DIRECTION_BOTH;
171                                 $dir_icon = 'images/lrarrow.gif';
172                                 $alt_text = t('Mutual Friendship');
173                         }
174                         else {
175                                 $direction = DIRECTION_IN;
176                                 $dir_icon = 'images/larrow.gif';
177                                 $alt_text = t('is a fan of yours');
178                         }
179                 }
180                 else {
181                         $direction = DIRECTION_OUT;
182                         $dir_icon = 'images/rarrow.gif';
183                         $alt_text = t('you are a fan of');
184                 }
185
186                 $o .= replace_macros($tpl,array(
187                         '$poll_interval' => contact_poll_interval($r[0]['priority']),
188                         '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00') 
189                                 ? t('Never') 
190                                 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
191                         '$profile_select' => contact_profile_assign($r[0]['profile-id']),
192                         '$contact_id' => $r[0]['id'],
193                         '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
194                         '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
195                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
196                         '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
197                         '$rating' => contact_reputation($r[0]['rating']),
198                         '$reason' => $r[0]['reason'],
199                         '$groups' => '', // group_selector(),
200                         '$photo' => $r[0]['photo'],
201                         '$name' => $r[0]['name'],
202                         '$dir_icon' => $dir_icon,
203                         '$alt_text' => $alt_text,
204                         '$url' => (($direction != DIRECTION_OUT) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
205
206                 ));
207
208                 return $o;
209
210         }
211
212
213         if(($a->argc == 2) && ($a->argv[1] == 'all'))
214                 $sql_extra = '';
215         else
216                 $sql_extra = " AND `blocked` = 0 ";
217
218         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
219
220         $tpl = file_get_contents("view/contacts-top.tpl");
221         $o .= replace_macros($tpl,array(
222                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
223                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
224                 '$search' => $search,
225                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
226                 '$submit' => t('Find'),
227                 '$cmd' => $a->cmd
228
229
230         )); 
231
232         if($search)
233                 $search = dbesc($search.'*');
234         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
235
236
237         switch($sort_type) {
238                 case DIRECTION_BOTH :
239                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
240                         break;
241                 case DIRECTION_IN :
242                         $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
243                         break;
244                 case DIRECTION_OUT :
245                         $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
246                         break;
247                 case DIRECTION_NONE :
248                 default:
249                         $sql_extra2 = '';
250                         break;
251         }
252
253         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
254                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
255                 intval($_SESSION['uid']));
256         if(count($r))
257                 $a->set_pager_total($r[0]['total']);
258
259         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
260                 intval($_SESSION['uid']),
261                 intval($a->pager['start']),
262                 intval($a->pager['itemspage'])
263         );
264
265         if(count($r)) {
266
267                 $tpl = file_get_contents("view/contact_template.tpl");
268
269                 foreach($r as $rr) {
270                         if($rr['self'])
271                                 continue;
272                         $direction = '';
273                         if(strlen($rr['issued-id'])) {
274                                 if(strlen($rr['dfrn-id'])) {
275                                         $direction = DIRECTION_BOTH;
276                                         $dir_icon = 'images/lrarrow.gif';
277                                         $alt_text = t('Mutual Friendship');
278                                 }
279                                 else {
280                                         $direction = DIRECTION_IN;
281                                         $dir_icon = 'images/larrow.gif';
282                                         $alt_text = t('is a fan of yours');
283                                 }
284                         }
285                         else {
286                                 $direction = DIRECTION_OUT;
287                                 $dir_icon = 'images/rarrow.gif';
288                                 $alt_text = t('you are a fan of');
289                         }
290
291                         $o .= replace_macros($tpl, array(
292                                 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
293                                 '$edit_hover' => t('Edit contact'),
294                                 '$id' => $rr['id'],
295                                 '$alt_text' => $alt_text,
296                                 '$dir_icon' => $dir_icon,
297                                 '$thumb' => $rr['thumb'], 
298                                 '$name' => $rr['name'],
299                                 '$url' => (($direction != DIRECTION_OUT) ? "redir/{$rr['id']}" : $rr['url'] )
300                         ));
301                 }
302                 $o .= '<div id="contact-edit-end"></div>';
303
304         }
305         $o .= paginate($a);
306         return $o;
307 }